﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using Users;
using Lists;
using Sim;


namespace Lists
{
    public class tourneyList
    {
        static public List<Tourney> _TourneyList { get; set; }
        
        static tourneyList()
        {
            _TourneyList = new List<Tourney>();
        }

        static public void Add(Tourney t)
        {
            _TourneyList.Add(t);
            SerializeToXML();
        }

        static public void SerializeToXML()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List<Tourney>), new XmlRootAttribute("TOURNEYS"));
            TextWriter textWriter = new StreamWriter("tourneys.xml");
            serializer.Serialize(textWriter, _TourneyList);
            textWriter.Close();
        }

        static public void DeserializeFromXML()
        {
            _TourneyList.Clear();
            XmlSerializer deserializer = new XmlSerializer(typeof(List<Tourney>), new XmlRootAttribute("TOURNEYS"));
            TextReader textReader = new StreamReader("tourneys.xml");
            _TourneyList = (List<Tourney>)deserializer.Deserialize(textReader);
            textReader.Close();
        }
    }
}
